package top.igotcha.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.StringUtils;
import top.igotcha.eduservice.entity.EduComment;
import top.igotcha.eduservice.entity.EduTeacher;
import top.igotcha.eduservice.entity.vo.CommentQueryVo;
import top.igotcha.eduservice.mapper.EduCommentMapper;
import top.igotcha.eduservice.service.EduCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author Gotcha
 * @since 2021-08-15
 */
@Service
public class EduCommentServiceImpl extends ServiceImpl<EduCommentMapper, EduComment> implements EduCommentService {

    @Override
    public void pageComentCondition(Page<EduComment> pageParam, CommentQueryVo queryVo) {
        QueryWrapper<EduComment> queryWrapper = new QueryWrapper<>();

        if (queryVo == null){
            baseMapper.selectPage(pageParam, queryWrapper);
            return;
        }
        String id = queryVo.getId();
        String courseId = queryVo.getCourseId();
        String teacherId = queryVo.getTeacherId();
        String memberId = queryVo.getMemberId();
        String nickname = queryVo.getNickname();
        String content = queryVo.getContent();

        if (!StringUtils.isEmpty(id) ) {
            queryWrapper.eq("id", id);
        }
        if (!StringUtils.isEmpty(courseId) ) {
            queryWrapper.eq("course_id", courseId);
        }
        if (!StringUtils.isEmpty(teacherId) ) {
            queryWrapper.eq("teacher_id", teacherId);
        }
        if (!StringUtils.isEmpty(memberId) ) {
            queryWrapper.eq("member_id", memberId);
        }
        if (!StringUtils.isEmpty(nickname)) {
            queryWrapper.like("nickname", nickname);
        }
        if (!StringUtils.isEmpty(content)) {
            queryWrapper.like("content", content);
        }
        baseMapper.selectPage(pageParam, queryWrapper);
    }
}
